#include "Warrior.h"

#pragma region Warrior
void Warrior::initialize() {
    if (!m_fromSave)
    {
        skills.emplace_back("猛击", "强力一击", 10, 15, 0);
        equipments.emplace_back("铁剑", "新手铁剑", 5, 0, 0);
        applyEquipmentBonuses();
    }
    
}

Warrior::Warrior(const std::string& name, const std::string& info)
    : Character(name, info, 1500, 10, 15, 100) {
    initialize();
}

Warrior::Warrior(const std::string& name, const std::string& info,
    int maxHealth, int attack, int defense, int maxMP)
    : Character(name, info, maxHealth, attack, defense, maxMP) {
    initialize();
}

void Warrior::uniqueEffect() {
    std::cout << "战士的怒火燃烧，攻击力暂时提升 3 点！" << std::endl;
    tempAtk = 3;
    baseAttack += 3;
}

void Warrior::Attack(Monster& monster) {
    Character::Attack(monster);
}

void Warrior::EndTurn() {
    baseAttack -= tempAtk;
    tempAtk = 0;
    Character::EndTurn();
}

Character* Warrior::clone() const {
    return new Warrior(*this);
}

std::string Warrior::getType() const {
    return "Warrior";
}
#pragma endregion 

#pragma region Mage
void Mage::initialize() {
    
    if (!m_fromSave)
    {
        skills.emplace_back("火球术", "发射火球造成魔法伤害", 20, 30, 0);
        equipments.emplace_back("法杖", "新手法杖", 0, 0, 0);
        applyEquipmentBonuses();
    }
}

Mage::Mage(const std::string& name, const std::string& info)
    : Character(name, info, 800, 8, 8, 200) {
    initialize();
}

Mage::Mage(const std::string& name, const std::string& info,
    int maxHealth, int attack, int defense, int maxMP)
    : Character(name, info, maxHealth, attack, defense, maxMP) {
    initialize();
}



void Mage::uniqueEffect() {
    int oldMP = mp;
    mp = std::min(maxMP, mp + regenMP);
    std::cout << "法师冥想，回复 " << (mp - oldMP) << " 点 MP！" << std::endl;
}

void Mage::Attack(Monster& monster) {
    uniqueEffect();
    Character::Attack(monster);
}

void Mage::EndTurn() {
    Character::EndTurn();
}

Character* Mage::clone() const {
    return new Mage(*this);
}

std::string Mage::getType() const {
    return "Mage";
}
#pragma endregion

#pragma region Archer
void Archer::initialize() {
    
    if (!m_fromSave)
    {
        skills.emplace_back("精准射击", "精准的一箭，造成高额伤害", 15, 25, 0);
        equipments.emplace_back("长弓", "新手长弓", 3, 0, 0);
        applyEquipmentBonuses();
    }
}

Archer::Archer(const std::string& name, const std::string& info)
    : Character(name, info, 1000, 12, 10, 80) {
    initialize();
}

Archer::Archer(const std::string& name, const std::string& info,
    int maxHealth, int attack, int defense, int maxMP)
    : Character(name, info, maxHealth, attack, defense, maxMP) {
    initialize();
}

void Archer::uniqueEffect() {
    if (std::rand() % 100 < piercingChance) {
        std::cout << "弓箭手的箭矢产生了暴击！" << std::endl;
        tempAtk = baseAttack;
        baseAttack += tempAtk;
    }
}

void Archer::Attack(Monster& monster) {
    uniqueEffect();
    Character::Attack(monster);
}

void Archer::EndTurn() {
    Character::EndTurn();
    baseAttack -= tempAtk;
    tempAtk = 0;
}

Character* Archer::clone() const {
    return new Archer(*this);
}

std::string Archer::getType() const {
    return "Archer";
}
#pragma endregion
